home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dviselect / box.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-16  |  13.5 KB  |  396 lines

  1. /*
  2.  * Copyright (c) 1987 University of Maryland Department of Computer Science.
  3.  * All rights reserved.  Permission to copy for any purpose is hereby granted
  4.  * so long as this copyright notice remains intact.
  5.  */
  6.  
  7. /* Box structures */
  8.  
  9. /* Magic constants.  Note that these are stored into `scaled' types. */
  10. #define RunningRule (-(1 << 30))
  11. #define MFracDefaultThickness (1 << 31)    /* => default rule thickness */
  12.  
  13. /* Magic penalty values */
  14. #define InfPenalty 10000    /* infinity---no break at all */
  15. #define EjectPenalty (-10000)    /* negative infinity---forced break */
  16.  
  17. /* Ordinary list types */
  18. #define CharNode    0    /* character; also math char */
  19. #define HListNode    1    /* a horizontal list */
  20. #define VListNode    2    /* a vertical list */
  21. #define RuleNode    3    /* a rule */
  22. #define InsertNode    4    /* an insertion */
  23. #define MarkNode    5    /* a mark */
  24. #define AdjustNode    6    /* a \vadjust */
  25. #define LigatureNode    7    /* a ligature */
  26. #define DiscretionaryNode 8    /* a discretionary break */
  27. #define WhatsitNode    9    /* a "whatsit" */
  28. #define BeginMathNode    10    /* a begin-math */
  29. #define EndMathNode    11    /* an end-math */
  30. #define GlueNode    12    /* link to glue */
  31. #define KernNode    13    /* kerning */
  32. #define PenaltyNode    14    /* penalty */
  33. #define UnsetAlignNode    15    /* \halign or \valign that is incomplete */
  34.  
  35. /* Types arising only in math lists */
  36. #define MathAtom    16    /* math atom */
  37. #define MathStyle    17    /* math style change */
  38. #define MathFraction    18    /* math fraction */
  39. #define MathLeft    19    /* math left delimiter \left */
  40. #define MathRight    20    /* math right delimiter \right */
  41. #define MathChoice    21    /* math 4-way choice */
  42. #define MathSubList    22    /* math list, possibly empty */
  43. #define MathSubBox    23    /* math box (\hlist or \vlist) */
  44.  
  45. /* Kinds of math atoms */
  46. enum MKind {
  47.     MKindOrd, MKindOp, MKindOpLimits, MKindOpNoLimits, MKindBin, MKindRel,
  48.     MKindOpen, MKindClose, MKindPunct, MKindInner, MKindOver, MKindUnder,
  49.     MKindAcc, MKindRad, MKindVCent
  50. };
  51.  
  52. /* Math text styles */
  53. #define MStyleCramped    1    /* added to others to get cramped style */
  54. #define MStyleDisplay    0    /* display style */
  55. #define MStyleText    2    /* text style */
  56. #define MStyleScript    4    /* script style */
  57. #define MStyleSScript    6    /* scriptscript style */
  58.  
  59. /*
  60.  * A font and character.  Note that these limit the number of fonts and
  61.  * characters/font to 256.
  62.  */
  63. struct fontchar {
  64.     char    fc_font;        /* font index */
  65.     char    fc_char;        /* character index within the font */
  66. };
  67.  
  68. /* a box */
  69. struct box {
  70.     scaled    bx_width;        /* width of the box */
  71.     scaled    bx_depth;        /* depth of the box */
  72.     scaled    bx_height;        /* height of the box */
  73.     scaled    bx_offset;        /* offset (lower if h, right if v) */
  74.     struct    node *bx_contents;    /* contents of the box */
  75.     int    bx_glueorder;        /* -3=>minus hfilll; 3=>plus hfilll */
  76.     float    bx_glueset;        /* glue setting ratio */
  77. };
  78.  
  79. /* a rule */
  80. struct rule {
  81.     scaled    ru_width;        /* width of the rule */
  82.     scaled    ru_depth;        /* depth of the rule */
  83.     scaled    ru_height;        /* height of the rule */
  84. };
  85.  
  86. /* an insert */
  87. struct insert {
  88.     int    ins_number;        /* 0..254 (I hope) */
  89.     i32    ins_floatingpenalty;    /* \floatingpenalty for this insert */
  90.     scaled    ins_naturalheightplusdepth;    /* what more can I say? */
  91.     scaled    ins_splitmaxdepth;    /* \splitmaxdepth for this insert */
  92.     struct    node *ins_splittopskip;    /* \splittopskip for this insert */
  93.     struct    node *ins_contents;    /* insertion contents */
  94. };
  95.  
  96. /* a ligature */
  97. struct ligature {
  98.     struct    fontchar lig_fc;    /* the ligature character */
  99.     struct    node *lig_orig;        /* the original set of characters */
  100. };
  101.  
  102. /* a discretionary break */
  103. struct discret {
  104.     struct    node *disc_prebrk;    /* characters to precede break */
  105.     struct    node *disc_postbrk;    /* characters to follow break */
  106.     int    disc_replaces;        /* replaces this many nodes */
  107. };
  108.  
  109. /* a whatsit */
  110. struct whatsit {
  111.     int    wh_type;        /* type of whatsit */
  112.     char    *wh_other;        /* other stuff */
  113. };
  114.  
  115. /*
  116.  * A glue specification.  There may be multiple pointers to this glue spec,
  117.  * so we have a reference count attached.
  118.  */
  119. struct gluespec {
  120.     int    gl_refcount;        /* # pointers to here */
  121.     scaled    gl_width;        /* normal width */
  122.     scaled    gl_stretch;        /* strechability */
  123.     scaled    gl_shrink;        /* shrinkability */
  124.     short    gl_stretchorder;    /* 0..3 for <>, fil, fill, filll */
  125.     short    gl_shrinkorder;        /* same */
  126. };
  127.  
  128. /* a link-to-glue node */
  129. #define GlueIsNormal    0        /* ordinary glue */
  130. #define GlueIsSkip    1        /* \hskip or \vskip */
  131. #define GlueIsNonScript    2        /* \nonscript */
  132. #define GlueIsMuGlue    3        /* mu glue */
  133. #define GlueIsALeaders    4        /* aligned leaders */
  134. #define GlueIsCLeaders    5        /* centered leaders */
  135. #define GlueIsXLeaders    6        /* expanded leaders */
  136. struct gluenode {
  137.     int    gn_type;        /* special glue types */
  138.     struct    node *gn_glue;        /* the glue itself */
  139.     struct    BoundName *gn_skip;    /* skip parameter that generated it */
  140.     struct    box *gn_leaderbox;    /* leader box if leaders */
  141. };
  142.  
  143. /* a kern */
  144. #define ImplicitKern    0        /* kerning for things like "AV" */
  145. #define ExplicitKern    1        /* \kern or italic correction */
  146. #define MKern        2        /* \mkern */
  147. struct kern {
  148.     int    kern_type;        /* type of kern */
  149.     scaled    kern_width;        /* width of kern */
  150. };
  151.  
  152. /*
  153.  * An unset (incomplete) alignment (\halign or \valign).
  154.  * This looks to be the largest node type, so I am using 'char' and 'short'
  155.  * to try to keep it small...
  156.  */
  157. struct unsetalign {
  158.     scaled    unset_width;        /* width of the unset box */
  159.     scaled    unset_depth;        /* depth of the unset box */
  160.     scaled    unset_height;        /* height of the unset box */
  161.     struct    node *unset_contents;    /* contents of the unset box */
  162.     scaled    unset_glueshrink;    /* total glue shrink */
  163.     scaled    unset_gluestretch;    /* total glue stretch */
  164.     char    unset_shrinkorder;    /* glue shrink order */
  165.     char    unset_stretchorder;    /* glue stretch order */
  166.     short    unset_spancount;    /* the number of spanned columns */
  167. };
  168.  
  169. /* a token list */
  170. struct toklist {
  171.     int    tok_refcount;        /* the number of references */
  172.     struct    node *tok_list;        /* the tokens or the macro def'n */
  173. };
  174.  
  175. /* Math delimiter */
  176. struct delim {
  177.     char    smallfam;        /* family number for small char */
  178.     char    smallchar;        /* character in small family */
  179.     char    largefam;        /* family number for large char */
  180.     char    largechar;        /* character in large family */
  181. };
  182.  
  183. /* Math atoms, radicals, \left s, \right s, accents */
  184. struct matom {
  185.     enum    MKind kind;        /* atom kind (if not \left, \right) */
  186.     struct    node *nucleus;        /* nucleus */
  187.     struct    node *supscr;        /* superscript (optional) */
  188.     struct    node *subscr;        /* subscript (optional) */
  189.     struct    delim delimiter;    /* delimiter(s) (optional) */
  190.     /* accents are stored in the small delim */
  191. };
  192.  
  193. /* Math fraction */
  194. struct mfrac {
  195.     struct    node *numerator;    /* numerator */
  196.     struct    node *denominator;    /* denominator */
  197.     scaled    thickness;        /* dividing rule thickness */
  198.     struct    delim leftdelim;    /* left delimiter (optional) */
  199.     struct    delim rightdelim;    /* right delimiter (optional) */
  200. };
  201.  
  202. /* Math choice */
  203. struct mchoice {
  204.     struct    node *ifdisplay;
  205.     struct    node *iftext;
  206.     struct    node *ifscript;
  207.     struct    node *ifsscript;
  208. };
  209.  
  210. /*
  211.  * This structure exists mainly for `sizeof'.  Character nodes are by far the
  212.  * most common nodes, so to save memory space, nodes of type CharNode are kept
  213.  * in a separate free list and do not get a full size node.  This means that
  214.  * node lists must be handled carefully, but that is already necessary, so it
  215.  * is no loss.
  216.  */
  217. struct charnode {
  218.     struct    node *next;
  219.     short    type;
  220.     struct    fontchar fc;
  221. };
  222.  
  223. /*
  224.  * A node in a list.  Note that the first part of this structure is shared
  225.  * with the struct charnode.
  226.  */
  227. struct node {
  228.     struct    node *next;        /* next in linked list */
  229.     short    type;            /* type of this node */
  230.     struct    fontchar fc;        /* value iff char */
  231.     union {
  232.         struct    box un_box;        /* value iff box */
  233.         struct    rule un_rule;        /* value iff rule */
  234.         struct    insert un_ins;        /* value iff insert */
  235.         struct    toklist *un_mark;    /* value iff mark */
  236.         struct    ligature un_lig;    /* value iff ligature */
  237.         struct    discret un_disc;    /* value iff discret. brk */
  238.         struct    whatsit un_whatsit;    /* value iff whatsit */
  239.         struct    gluespec un_gluespec;    /* value iff glue */
  240.         struct    gluenode un_gluenode;    /* value iff link to glue */
  241.         struct    kern un_kern;        /* value iff kern */
  242.         i32    un_integer;        /* value if  integer */
  243.         struct    unsetalign un_unset;    /* value iff unset alignment */
  244.         struct    matom un_matom;        /* value if  math atom */
  245.         struct    mfrac un_mfrac;        /* value iff math fraction */
  246.         struct    mchoice un_mchoice;    /* value iff math choice */
  247.         struct    node *un_node;        /* value if  node list */
  248.     } node_un;
  249. };
  250.  
  251. /* Shorthand */
  252. #define FC   fc
  253. #define Font fc.fc_font
  254. #define Char fc.fc_char
  255.  
  256. #define BoxWidth     node_un.un_box.bx_width
  257. #define BoxDepth     node_un.un_box.bx_depth
  258. #define BoxHeight    node_un.un_box.bx_height
  259. #define BoxOffset    node_un.un_box.bx_offset
  260. #define BoxContents  node_un.un_box.bx_contents
  261. #define BoxGlueOrder node_un.un_box.bx_glueorder
  262. #define BoxGlueSet   node_un.un_box.bx_glueset
  263.  
  264. #define RuleWidth  node_un.un_rule.ru_width
  265. #define RuleDepth  node_un.un_rule.ru_depth
  266. #define RuleHeight node_un.un_rule.ru_height
  267.  
  268. #define InsertNumber                 node_un.un_ins.ins_number
  269. #define InsertFloatingPenalty        node_un.un_ins.ins_floatingpenalty
  270. #define InsertNaturalHeightPlusDepth node_un.un_ins.ins_naturalheightplusdepth
  271. #define InsertSplitMaxDepth          node_un.un_ins.ins_splitmaxdepth
  272. #define InsertSplitTopSkip           node_un.un_ins.ins_splittopskip
  273. #define InsertContents               node_un.un_ins.ins_contents
  274.  
  275. #define Mark node_un.un_mark
  276.  
  277. #define LigatureFC   node_un.un_lig.lig_fc
  278. #define LigatureOrig node_un.un_lig.lig_orig
  279.  
  280. #define DiscretPreBreak  node_un.un_disc.disc_prebrk
  281. #define DiscretPostBreak node_un.un_disc.disc_postbrk
  282. #define DiscretReplaces  node_un.un_disc.disc_replaces
  283.  
  284. #define WhatsitType  node_un.un_whatsit.wh_type
  285. #define WhatsitOther node_un.un_whatsit.wh_other
  286.  
  287. #define GlueRefCount     node_un.un_gluespec.gl_refcount
  288. #define GlueWidth        node_un.un_gluespec.gl_width
  289. #define GlueStretch      node_un.un_gluespec.gl_stretch
  290. #define GlueShrink       node_un.un_gluespec.gl_shrink
  291. #define GlueStretchOrder node_un.un_gluespec.gl_stretchorder
  292. #define GlueShrinkOrder  node_un.un_gluespec.gl_shrinkorder
  293.  
  294. #define Glue          node_un.un_gluenode.gn_glue
  295. #define GlueSkip      node_un.un_gluenode.gn_skip
  296. #define GlueType      node_un.un_gluenode.gn_type
  297. #define GlueLeaderBox node_un.un_gluenode.gn_leaderbox
  298.  
  299. #define KernWidth node_un.un_kern.kern_width
  300. #define KernType  node_un.un_kern.kern_type
  301.  
  302. #define Penalty node_un.un_integer
  303.  
  304. #define UnsetWidth        node_un.un_unset.unset_width
  305. #define UnsetDepth        node_un.un_unset.unset_depth
  306. #define UnsetHeight       node_un.un_unset.unset_height
  307. #define UnsetContents     node_un.un_unset.unset_contents
  308. #define UnsetGlueShrink   node_un.un_unset.unset_glueshrink
  309. #define UnsetGlueStretch  node_un.un_unset.unset_gluestretch
  310. #define UnsetShrinkOrder  node_un.un_unset.unset_shrinkorder
  311. #define UnsetStretchOrder node_un.un_unset.unset_stretchorder
  312. #define UnsetSpanCount    node_un.un_unset.unset_spancount
  313.  
  314. #define MAtomKind      node_un.un_matom.kind
  315. #define MAtomNucleus   node_un.un_matom.nucleus
  316. #define MAtomSupscr    node_un.un_matom.supscr
  317. #define MAtomSubscr    node_un.un_matom.subscr
  318. #define MAtomDelimiter node_un.un_matom.delimiter
  319. #define MAtomAccFam    node_un.un_matom.delimiter.smallfam
  320. #define MAtomAccChar   node_un.un_matom.delimiter.smallchar
  321.  
  322. #define MFracNumerator   node_un.un_mfrac.numerator
  323. #define MFracDenominator node_un.un_mfrac.denominator
  324. #define MFracThickness   node_un.un_mfrac.thickness
  325. #define MFracLeftDelim   node_un.un_mfrac.leftdelim
  326. #define MFracRightDelim  node_un.un_mfrac.rightdelim
  327.  
  328. #define MChoiceDisplay node_un.un_mchoice.ifdisplay
  329. #define MChoiceText    node_un.un_mchoice.iftext
  330. #define MChoiceScript  node_un.un_mchoice.ifscript
  331. #define MChoiceSScript node_un.un_mchoice.ifsscript
  332.  
  333. #define MStyle node_un.un_integer
  334.  
  335. #define MSub node_un.un_node
  336.  
  337. struct    node *FreeNodes;
  338. struct    node *FreeChars;
  339.  
  340. struct    node *MoreNodes();
  341. struct    node *MoreChars();
  342.  
  343. /*
  344.  * These macros quickly allocate and dispose of nodes.  Watch out; the
  345.  * arguments to NewNode and NewCharNode should be pointers that are to
  346.  * be filled in.  Moreover, the argument is accessed twice, so beware
  347.  * side effects!
  348.  */
  349. #define NewNode(n) \
  350.     if (((n) = FreeNodes) == NULL) \
  351.         (n) = MoreNodes(); \
  352.     else \
  353.         FreeNodes = (n)->next
  354.  
  355. #define NewCharNode(n) \
  356.     if (((n) = FreeChars) == NULL) \
  357.         (n) = MoreChars(); \
  358.     else \
  359.         FreeChars = (n)->next
  360.  
  361. #define FreeNode(n)    ((n)->next = FreeNodes, FreeNodes = (n))
  362. #define FreeChar(n)    ((n)->next = FreeChars, FreeChars = (n))
  363.  
  364. /* To free either a CharNode or a Node, use FreeEither! */
  365. #define FreeEither(n)    ((n)->type ? FreeNode(n) : FreeChar(n))
  366.  
  367. #define DelTokRef(p)    (--(p)->tok_refcount < 0 ? FlushList(p) : NULL)
  368. #define DelGlueRef(p)    (--(p)->GlueRefCount < 0 ? FreeNode(p) : NULL)
  369.  
  370. /* These determine the granularity of node allocation */
  371. #define NodeAllocSize    300    /* Nodes per MoreNodes() */
  372. #define CharAllocSize    2500    /* CharNodes per MoreChars() */
  373.  
  374. struct    node *CopyGlueSpec();
  375. struct    node *LinkToSkipParam();
  376. struct    node *LinkToGlueSpec();
  377. struct    node *LinkToCopyOfSkipParam();
  378.  
  379. #define NodeListDisplay(p) (s_addc('.'), ShowNodeList(p), s_delc())
  380.  
  381. /*
  382.  * The ordering of the types is important here, because it allows simple
  383.  * decisions for common operations.
  384.  */
  385. #define CanBreakAtGlue(n)    ((n)->type <  BeginMathNode)
  386. #define CanDiscardAfterBreak(n) ((n)->type >= BeginMathNode)
  387.  
  388. struct    node ZeroGlue;        /* the zero-amount glue (0pt) */
  389. struct    node FilGlue;        /* 0pt plus1fil minus0pt */
  390. struct    node FillGlue;        /* 0pt plus1fill minus0pt */
  391. struct    node SSGlue;        /* 0pt plus1fil minus1fil */
  392. struct    node FilNegGlue;    /* 0pt plus-1fil minus0pt */
  393. i32    ShowBoxMaxDepth;    /* max nesting depth in box displays */
  394. i32    ShowBoxMaxBreadth;    /* max number of items per list level */
  395. int    FontInShortDisplay;    /* the "current font" during a ShortDisplay */
  396.